In the following work we will explore how does compressing an image using SVD works. For this we will take an image and see how different compression work and how big the compression ratios are.
This work will be based on the above image. The picture is 654X650. We can also check that it is a full rank matrix (650) in all 3 color spaces using the rank command in matlab. So the original image needs
650*654*3
## [1] 1275300
Different numbers for storing the whole image.
For getting the low rank compression we will use the “compress.m” file modified (included in the folder) to export the image files and find the rank of the resulting matrices.
Given that in a compressed Matrix of rank k
\[ A_k=\sum_{i=1}^k\sigma_i \vec{u_k}\vec{v_k}^t \]
holds 1 item of information in \(\sigma_i\), items equal to the vertical size in \(\vec{u_i}\) and items equal to the horizontal size in \(\vec{v_i}\). Also note that this has to be done for all 3 colors so in total we need
\[ (650+654+1)3k \]
And we get a compression equivalent to
\[ \frac{(650+654+1)3k}{650*654*3} \] We can see a few select values in the following table.
V=data.frame(rank=c(1,2,10,40,100,325,650))
V %<>% mutate(comp_data=(650+654+1)*3*rank,comp_rate=comp_data/(650*654*3))
V
## rank comp_data comp_rate
## 1 1 3915 0.003069866
## 2 2 7830 0.006139732
## 3 10 39150 0.030698659
## 4 40 156600 0.122794637
## 5 100 391500 0.306986591
## 6 325 1272375 0.997706422
## 7 650 2544750 1.995412844
Note that when using half the rank uses almost the same information than the image itself and using the full rank uses almost twice as much as the original image.
The following shows the results of compressing the image using the first 40 SVD